(function() {
	var $dataList = $("#list"),
		listHtml = undefined,
		mouseFlag = false,
		postData = {},
		status = 0,
		refund = 0,
		curPage = 1,
		stations = [];
	var $searchForm = $("#search-form");
	var _this = {
		list: function() {
			postData.page = curPage;
			postData.status = status;
			postData.refund = refund; //是否开退款查询
			App.ajax({
				data: postData,
				resUrl: "/order/getOrderList",
				callback: function(rb) {
					if(!rb.status) return;
					$(".main-container").scrollTop(0);
					//$dataList.empty();
					var data = rb.data || [];
					$.each(data.list || [], function(i, dtl) {
						
					});

					// 分页
					require(['laypage'], function(laypage) {
						laypage({
							cont: 'page-body', //容器。值支持id名、原生dom对象，jquery对象。【如该容器为】：<div id="page1"></div>
							pages: data.totalPage, //通过后台拿到的总页数
							curr: data.pageNumber || 1, //当前页
							groups: 10,
							last: data.totalPage,
							jump: function(obj, first) { //触发分页后的回调
								curPage = obj.curr;
								if(!first) {
									_this.list();
								}
							}
						});
					});
				}
			});
		},
		// 列表事件初始化
		initEventList: function() {
			// 用车信息点击，回调后执行用车信息列表初始化
			$("#list").delegate("[btn-type=info_vehicle]", 'click', function() {
				$(this).parents('.dtl-action').siblings('.vehicle_list_body').slideToggle(300)
			});
			// 修改点击
			App.delegate({
				btntype: "[btn-type=edit]",
				callback: function(data) {
					_this.renderingForm(data);
				}
			});
			// 特权修改点击
			App.delegate({
				btntype: "[btn-type=pri_edit]",
				callback: function(data) {
					_this.renderingForm(data);
				}
			});
			// 报价点击
			App.delegate({
				btntype: "[btn-type=offer]",
				callback: function(data) {
					_this.renderingForm(data);
				}
			});
			// 重新报价点击
			App.delegate({
				btntype: "[btn-type=reseat_offer]",
				callback: function(data) {
					_this.renderingForm(data);
				}
			});
			// 列表中的更多点击
			App.delegate({
				btntype: "[btn-type=more]",
				callback: function(data) {
					var opt = {
						content: $("#details_list_box").html(),
						submitBtn: "[hy-type-submit]",
						submit: function(from) {
							App.closeEntitySlider();
						},
						//滑动窗口打开时的回调
						callback: function(e) {
							$("#entitySlider .detail-brand").find("vl").html("更多");
						}
					};
					App.drawDetailPanel(opt);
				}
			});
			// 反馈无车点击
			$("#list").delegate("[btn-type=no_vehicle]", 'click', function() {
				var id = $(this).parents('tr').data('id');
				var msg = '是否确认向用户反馈无车？';
				var btnok = '确认'
				var _index = layer.confirm('<div style="margin: auto;width: 222px;">' + msg + '</div>', {
					type: 1,
					title: "反馈无车",
					area: ['300px', 'auto'], //宽高
					btn: [btnok, '取消']
				}, function() {
					// 确定后的删除操作，取到id，调用删除接口，成功后刷新表格
					App.ajax({
						data: {
							id: id
						},
						resUrl: 'ygxStudent/delete',
						callback: function(rb) {
							if(!rb.status) {
								layer.msg(rb.msg, {
									icon: 5
								});
								return;
							} else {
								layer.msg(rb.msg, {
									icon: 5
								});
								_this.list();
								layer.close(_index);
							}
						}
					});
				}, function() {
					// 取消
					layer.close(_index);
				});
			});
			// 确认排车点击
			$("#list").delegate("[btn-type=confirm_paiche]", 'click', function() {
				var id = $(this).parents('tr').data('id');
				var msg = '是否确认订单排车并将车辆信息通知给客户？';
				var btnok = '确认'
				var _index = layer.confirm('<div style="margin: auto;width: 222px;">' + msg + '</div>', {
					type: 1,
					title: "确认排车",
					area: ['300px', 'auto'], //宽高
					btn: [btnok, '取消']
				}, function() {
					// 确定后的删除操作，取到id，调用删除接口，成功后刷新表格
					App.ajax({
						data: {
							id: id
						},
						resUrl: 'ygxStudent/delete',
						callback: function(rb) {
							if(!rb.status) {
								layer.msg(rb.msg, {
									icon: 5
								});
								return;
							} else {
								layer.msg(rb.msg, {
									icon: 5
								});
								_this.list();
								layer.close(_index);
							}
						}
					});
				}, function() {
					// 取消
					layer.close(_index);
				});
			});
			// 取消订单点击
			$("#list").delegate("[btn-type=cancel_order]", 'click', function() {
				var html = $("#c_order_box").html();
				var $st = $(html);
				layer.confirm($st[0].outerHTML, {
					type: 0,
					title: "取消订单",
					closeBtn: 1,
					area: ['600px', '350px'], //宽高
					btn: ['确定', '取消'] //按钮
				}, function() {
					var $div = $("#alter-status-div");
					var stName = $div.find("[name=stationName]").val();
					var stTime = $div.find("[name=startTimestart]").val();
					var stOrder = $div.find("[name=stOrder]").val();
					if(!stName) {
						layer.msg('请填写站点名称!', {
							type: 1
						});
						return;
					}
					if(!stOrder) {
						layer.msg('请填写站点顺序!', {
							type: 1
						});
						return;
					}
					App.ajax({
						data: {
							lineId: lineId,
							stationId: stName,
							arriveTime: stTime,
							sequence: stOrder
						},
						resUrl: "ygxLineStation/add",
						callback: function(rb) {
							if(rb.code == 0) {
								layer.msg('成功', {
									icon: 1
								});
								_this.stList(lineId);
							} else {
								layer.msg(rb.msg || '失败', {
									icon: 5
								});
								var _index = layer.confirm('<div style="margin: auto;width: 222px;height:80px;font-size:18px;line-height:80px;text-align:center;">' + rb.msg + '</div>', {
									type: 1,
									title: "",
									area: ['300px', 'auto'], //宽高
									btn: ['确定']
								}, function() {
									layer.close(_index);
								});
							}
						}
					});
				}, function() {
					layer.msg('操作已取消', {
						icon: 7
					});
				});
			});
			// 订单操作日志
			App.delegate({
				selector: ".deails:eq(0)",
				btntype: "[btn-type=Journal]",
				callback: function(data) {
					window.open("/tool/wsdlfile.html?busNo=" + data.busNo);
				}
			});
		},
		// 顶部按钮事件初始化
		initEventHeadBtn: function(){
			// 新增点击
			App.delegate({
				btntype: "[btn-type=add_order]",
				callback: function(data) {
					_this.renderingForm();
				}
			});
			// 状态按钮点击
			$('#search-status').find("button").on("click", function(){
                $("#search-div").slideUp();
                $(".main-container").scrollTop(0);
				var $this = $(this);
				$('#search-status').find("button").removeClass("am-btn-default btn-info");
				$this.addClass("btn-info");
				status = $this.data("status");
				curPage = 1;
				_this.list();
			});		
			// 导出按钮点击
			$('#exportOrder').on('click', function(){
				
			})
			// 导出按钮点击
			$('#exportVehicle').on('click', function(){
				
			})
		},
		// 用车信息列表按钮初始化
		initEventCarList:function(){
			// 排车点击
			$("#list").delegate("[btn-type=paiche]", 'click', function() {
				var html = $("#paiche_box").html();
				var $st = $(html);
				layer.confirm($st[0].outerHTML, {
					type: 0,
					title: "取消订单",
					closeBtn: 1,
					area: ['600px', '350px'], //宽高
					btn: ['确定', '取消'] //按钮
				}, function() {
					var $div = $("#paiche-div");
					var stName = $div.find("[name=stationName]").val();
					var stTime = $div.find("[name=startTimestart]").val();
					var stOrder = $div.find("[name=stOrder]").val();
					if(!stName) {
						layer.msg('请填写站点名称!', {
							type: 1
						});
						return;
					}
					if(!stOrder) {
						layer.msg('请填写站点顺序!', {
							type: 1
						});
						return;
					}
					App.ajax({
						data: {
							lineId: lineId,
							stationId: stName,
							arriveTime: stTime,
							sequence: stOrder
						},
						resUrl: "ygxLineStation/add",
						callback: function(rb) {
							if(rb.code == 0) {
								layer.msg('成功', {
									icon: 1
								});
								_this.stList(lineId);
							} else {
								layer.msg(rb.msg || '失败', {
									icon: 5
								});
								var _index = layer.confirm('<div style="margin: auto;width: 222px;height:80px;font-size:18px;line-height:80px;text-align:center;">' + rb.msg + '</div>', {
									type: 1,
									title: "",
									area: ['300px', 'auto'], //宽高
									btn: ['确定']
								}, function() {
									layer.close(_index);
								});
							}
						}
					});
				}, function() {
					layer.msg('操作已取消', {
						icon: 7
					});
				});
				// 运输公司select2初始化
				$('#parentPhone_e1').select2({
					placeholder: "请选择",
					minimumInputLength: 0,
					allowClear: true,
					ajax: {
						url: App.getServicePath + 'station/select2', 
						dataType: 'json',
						data: function(term, page) {
							return {
								key: encodeURI(term)
							};
						},
						results: function(data, page) {
							return {
								results: data.data
							};
						},
						processResults: function(data, params) {
							params.page = params.page || 1;
	
							return {
								results: data.results,
								pagination: {
									more: (params.page * 10) < data.count_filtered
								}
							};
						}
					}
				});
				// 运输公司select2初始化
				$('#parentPhone_e2').select2({
					placeholder: "请选择",
					minimumInputLength: 0,
					allowClear: true,
					ajax: {
						url: App.getServicePath + 'station/select2', 
						dataType: 'json',
						data: function(term, page) {
							return {
								key: encodeURI(term)
							};
						},
						results: function(data, page) {
							return {
								results: data.data
							};
						},
						processResults: function(data, params) {
							params.page = params.page || 1;
	
							return {
								results: data.results,
								pagination: {
									more: (params.page * 10) < data.count_filtered
								}
							};
						}
					}
				});
				// 运输公司select2初始化
				$('#parentPhone_e3').select2({
					placeholder: "请选择",
					minimumInputLength: 0,
					allowClear: true,
					ajax: {
						url: App.getServicePath + 'station/select2', 
						dataType: 'json',
						data: function(term, page) {
							return {
								key: encodeURI(term)
							};
						},
						results: function(data, page) {
							return {
								results: data.data
							};
						},
						processResults: function(data, params) {
							params.page = params.page || 1;
	
							return {
								results: data.results,
								pagination: {
									more: (params.page * 10) < data.count_filtered
								}
							};
						}
					}
				});
				// 运输公司select2初始化
				$('#parentPhone_e4').select2({
					placeholder: "请选择",
					minimumInputLength: 0,
					allowClear: true,
					ajax: {
						url: App.getServicePath + 'station/select2', 
						dataType: 'json',
						data: function(term, page) {
							return {
								key: encodeURI(term)
							};
						},
						results: function(data, page) {
							return {
								results: data.data
							};
						},
						processResults: function(data, params) {
							params.page = params.page || 1;
	
							return {
								results: data.results,
								pagination: {
									more: (params.page * 10) < data.count_filtered
								}
							};
						}
					}
				});
			});
			// 查看合同
			// 生成合同点击
			$("#list").delegate("[btn-type=create_contract]", 'click', function() {
				var id = $(this).parents('tr').data('id');
				var msg = '是否确认报班并上报省厅生成电子合同？';
				var btnok = '确认'
				var _index = layer.confirm('<div style="margin: auto;width: 222px;">' + msg + '</div>', {
					type: 1,
					title: "报班",
					area: ['300px', 'auto'], //宽高
					btn: [btnok, '取消']
				}, function() {
					// 确定后的删除操作，取到id，调用删除接口，成功后刷新表格
					App.ajax({
						data: {
							id: id
						},
						resUrl: 'ygxStudent/delete',
						callback: function(rb) {
							if(!rb.status) {
								layer.msg(rb.msg, {
									icon: 5
								});
								return;
							} else {
								layer.msg(rb.msg, {
									icon: 5
								});
								_this.list();
								layer.close(_index);
							}
						}
					});
				}, function() {
					// 取消
					layer.close(_index);
				});
			});
			// 重新排车
			$("#list").delegate("[btn-type=reseat_paiche]", 'click', function() {
				var html = $("#paiche_box").html();
				var $st = $(html);
				layer.confirm($st[0].outerHTML, {
					type: 0,
					title: "取消订单",
					closeBtn: 1,
					area: ['600px', '350px'], //宽高
					btn: ['确定', '取消'] //按钮
				}, function() {
					var $div = $("#paiche-div");
					var stName = $div.find("[name=stationName]").val();
					var stTime = $div.find("[name=startTimestart]").val();
					var stOrder = $div.find("[name=stOrder]").val();
					if(!stName) {
						layer.msg('请填写站点名称!', {
							type: 1
						});
						return;
					}
					if(!stOrder) {
						layer.msg('请填写站点顺序!', {
							type: 1
						});
						return;
					}
					App.ajax({
						data: {
							lineId: lineId,
							stationId: stName,
							arriveTime: stTime,
							sequence: stOrder
						},
						resUrl: "ygxLineStation/add",
						callback: function(rb) {
							if(rb.code == 0) {
								layer.msg('成功', {
									icon: 1
								});
								_this.stList(lineId);
							} else {
								layer.msg(rb.msg || '失败', {
									icon: 5
								});
								var _index = layer.confirm('<div style="margin: auto;width: 222px;height:80px;font-size:18px;line-height:80px;text-align:center;">' + rb.msg + '</div>', {
									type: 1,
									title: "",
									area: ['300px', 'auto'], //宽高
									btn: ['确定']
								}, function() {
									layer.close(_index);
								});
							}
						}
					});
				}, function() {
					layer.msg('操作已取消', {
						icon: 7
					});
				});
				// 运输公司select2初始化
				$('#parentPhone_e1').select2({
					placeholder: "请选择",
					minimumInputLength: 0,
					allowClear: true,
					ajax: {
						url: App.getServicePath + 'station/select2', 
						dataType: 'json',
						data: function(term, page) {
							return {
								key: encodeURI(term)
							};
						},
						results: function(data, page) {
							return {
								results: data.data
							};
						},
						processResults: function(data, params) {
							params.page = params.page || 1;
	
							return {
								results: data.results,
								pagination: {
									more: (params.page * 10) < data.count_filtered
								}
							};
						}
					}
				});
				// 运输公司select2初始化
				$('#parentPhone_e2').select2({
					placeholder: "请选择",
					minimumInputLength: 0,
					allowClear: true,
					ajax: {
						url: App.getServicePath + 'station/select2', 
						dataType: 'json',
						data: function(term, page) {
							return {
								key: encodeURI(term)
							};
						},
						results: function(data, page) {
							return {
								results: data.data
							};
						},
						processResults: function(data, params) {
							params.page = params.page || 1;
	
							return {
								results: data.results,
								pagination: {
									more: (params.page * 10) < data.count_filtered
								}
							};
						}
					}
				});
				// 运输公司select2初始化
				$('#parentPhone_e3').select2({
					placeholder: "请选择",
					minimumInputLength: 0,
					allowClear: true,
					ajax: {
						url: App.getServicePath + 'station/select2', 
						dataType: 'json',
						data: function(term, page) {
							return {
								key: encodeURI(term)
							};
						},
						results: function(data, page) {
							return {
								results: data.data
							};
						},
						processResults: function(data, params) {
							params.page = params.page || 1;
	
							return {
								results: data.results,
								pagination: {
									more: (params.page * 10) < data.count_filtered
								}
							};
						}
					}
				});
				// 运输公司select2初始化
				$('#parentPhone_e4').select2({
					placeholder: "请选择",
					minimumInputLength: 0,
					allowClear: true,
					ajax: {
						url: App.getServicePath + 'station/select2', 
						dataType: 'json',
						data: function(term, page) {
							return {
								key: encodeURI(term)
							};
						},
						results: function(data, page) {
							return {
								results: data.data
							};
						},
						processResults: function(data, params) {
							params.page = params.page || 1;
	
							return {
								results: data.results,
								pagination: {
									more: (params.page * 10) < data.count_filtered
								}
							};
						}
					}
				});
			});
			// 取消用车点击
			$("#list").delegate("[btn-type=cancel_vehicle]", 'click', function() {
				var html = $("#c_vehicle_box").html();
				var $st = $(html);
				layer.confirm($st[0].outerHTML, {
					type: 0,
					title: "取消订单",
					closeBtn: 1,
					area: ['600px', '350px'], //宽高
					btn: ['确定', '取消'] //按钮
				}, function() {
					var $div = $("#alter-status-div");
					var stName = $div.find("[name=stationName]").val();
					var stTime = $div.find("[name=startTimestart]").val();
					var stOrder = $div.find("[name=stOrder]").val();
					if(!stName) {
						layer.msg('请填写站点名称!', {
							type: 1
						});
						return;
					}
					if(!stOrder) {
						layer.msg('请填写站点顺序!', {
							type: 1
						});
						return;
					}
					App.ajax({
						data: {
							lineId: lineId,
							stationId: stName,
							arriveTime: stTime,
							sequence: stOrder
						},
						resUrl: "ygxLineStation/add",
						callback: function(rb) {
							if(rb.code == 0) {
								layer.msg('成功', {
									icon: 1
								});
								_this.stList(lineId);
							} else {
								layer.msg(rb.msg || '失败', {
									icon: 5
								});
								var _index = layer.confirm('<div style="margin: auto;width: 222px;height:80px;font-size:18px;line-height:80px;text-align:center;">' + rb.msg + '</div>', {
									type: 1,
									title: "",
									area: ['300px', 'auto'], //宽高
									btn: ['确定']
								}, function() {
									layer.close(_index);
								});
							}
						}
					});
				}, function() {
					layer.msg('操作已取消', {
						icon: 7
					});
				});
			});
			// 修改费用点击
			$("#list").delegate("[btn-type=edit_cost]", 'click', function() {
				var html = $("#edit_cost_box").html();
				var $st = $(html);
				layer.confirm($st[0].outerHTML, {
					type: 0,
					title: "取消订单",
					closeBtn: 1,
					area: ['600px', '480px'], //宽高
					btn: ['确定', '取消'] //按钮
				}, function() {
					var $div = $("#alter-status-div");
					var stName = $div.find("[name=stationName]").val();
					var stTime = $div.find("[name=startTimestart]").val();
					var stOrder = $div.find("[name=stOrder]").val();
					if(!stName) {
						layer.msg('请填写站点名称!', {
							type: 1
						});
						return;
					}
					if(!stOrder) {
						layer.msg('请填写站点顺序!', {
							type: 1
						});
						return;
					}
					App.ajax({
						data: {
							lineId: lineId,
							stationId: stName,
							arriveTime: stTime,
							sequence: stOrder
						},
						resUrl: "ygxLineStation/add",
						callback: function(rb) {
							if(rb.code == 0) {
								layer.msg('成功', {
									icon: 1
								});
								_this.stList(lineId);
							} else {
								layer.msg(rb.msg || '失败', {
									icon: 5
								});
								var _index = layer.confirm('<div style="margin: auto;width: 222px;height:80px;font-size:18px;line-height:80px;text-align:center;">' + rb.msg + '</div>', {
									type: 1,
									title: "",
									area: ['300px', 'auto'], //宽高
									btn: ['确定']
								}, function() {
									layer.close(_index);
								});
							}
						}
					});
				}, function() {
					layer.msg('操作已取消', {
						icon: 7
					});
				});
			});
			// 查看车辆位置点击
            App.delegate({
                btntype: "[btn-type='vehicle_pos']",
                callback: function (data) {
                    App.singleMap =data;
                    layer.open({
                        type: 2,
                        title: '查看地图位置',
                        shadeClose: true,
                        shade: false,
                        shade: 0.7,
                        area: ['914px', '636px'],
                        content: '/src/page/map/vehiclePos.html?v_=' + App.reandom()
                    });
                }
            });
            // 用车信息的更多点击
			App.delegate({
				btntype: "[btn-type=vehicle_more]",
				callback: function(data) {
					var opt = {
						content: $("#details_vehicle_box").html(),
						submitBtn: "[hy-type-submit]",
						submit: function(from) {
							App.closeEntitySlider();
						},
						//滑动窗口打开时的回调
						callback: function(e) {
							$("#entitySlider .detail-brand").find("vl").html("更多");
						}
					};
					App.drawDetailPanel(opt);
				}
			});
            // 发车点击
            $("#list").delegate("[btn-type=start_vehicle]", 'click', function() {
				var html = $("#start_vehicle_box").html();
				var $st = $(html);
				layer.confirm($st[0].outerHTML, {
					type: 0,
					title: "取消订单",
					closeBtn: 1,
					area: ['600px', '200px'], //宽高
					btn: ['确定', '取消'] //按钮
				}, function() {
					var $div = $("#alter-status-div");
					var stName = $div.find("[name=stationName]").val();
					var stTime = $div.find("[name=startTimestart]").val();
					var stOrder = $div.find("[name=stOrder]").val();
					if(!stName) {
						layer.msg('请填写站点名称!', {
							type: 1
						});
						return;
					}
					if(!stOrder) {
						layer.msg('请填写站点顺序!', {
							type: 1
						});
						return;
					}
					App.ajax({
						data: {
							lineId: lineId,
							stationId: stName,
							arriveTime: stTime,
							sequence: stOrder
						},
						resUrl: "ygxLineStation/add",
						callback: function(rb) {
							if(rb.code == 0) {
								layer.msg('成功', {
									icon: 1
								});
								_this.stList(lineId);
							} else {
								layer.msg(rb.msg || '失败', {
									icon: 5
								});
								var _index = layer.confirm('<div style="margin: auto;width: 222px;height:80px;font-size:18px;line-height:80px;text-align:center;">' + rb.msg + '</div>', {
									type: 1,
									title: "",
									area: ['300px', 'auto'], //宽高
									btn: ['确定']
								}, function() {
									layer.close(_index);
								});
							}
						}
					});
				}, function() {
					layer.msg('操作已取消', {
						icon: 7
					});
				});
			});
            // 结束点击
            $("#list").delegate("[btn-type=end_vehicle]", 'click', function() {
				var html = $("#end_vehicle_box").html();
				var $st = $(html);
				layer.confirm($st[0].outerHTML, {
					type: 0,
					title: "取消订单",
					closeBtn: 1,
					area: ['600px', '260px'], //宽高
					btn: ['确定', '取消'] //按钮
				}, function() {
					var $div = $("#alter-status-div");
					var stName = $div.find("[name=stationName]").val();
					var stTime = $div.find("[name=startTimestart]").val();
					var stOrder = $div.find("[name=stOrder]").val();
					if(!stName) {
						layer.msg('请填写站点名称!', {
							type: 1
						});
						return;
					}
					if(!stOrder) {
						layer.msg('请填写站点顺序!', {
							type: 1
						});
						return;
					}
					App.ajax({
						data: {
							lineId: lineId,
							stationId: stName,
							arriveTime: stTime,
							sequence: stOrder
						},
						resUrl: "ygxLineStation/add",
						callback: function(rb) {
							if(rb.code == 0) {
								layer.msg('成功', {
									icon: 1
								});
								_this.stList(lineId);
							} else {
								layer.msg(rb.msg || '失败', {
									icon: 5
								});
								var _index = layer.confirm('<div style="margin: auto;width: 222px;height:80px;font-size:18px;line-height:80px;text-align:center;">' + rb.msg + '</div>', {
									type: 1,
									title: "",
									area: ['300px', 'auto'], //宽高
									btn: ['确定']
								}, function() {
									layer.close(_index);
								});
							}
						}
					});
				}, function() {
					layer.msg('操作已取消', {
						icon: 7
					});
				});
			});
		},
		renderingForm: function( data ){
			var data = data || {};
			var opt = {
				content: $("#add-box").html(),
				submitBtn: "[hy-type-submit]",
				submit: function(from) {
					var params = from.serializeObject();
					params.id = data.id;
					if(!params.order_root) {
						layer.msg('请选择订单来源', {
							icon: 5
						});
						return false;
					}
					if( !$('.ent_customer_box').hasClass('ent_customer_active') ){
						params.qiyekehu = '';
					}
					if(!params.qiyekehu && $('.ent_customer_box').hasClass('ent_customer_active')) {
						layer.msg('请填写企业客户', {
							icon: 5
						});
						return false;
					}
					if(!(/^1[3|4|5|7|8][0-9]{9}$/.test(params.parentPhone)) || params.parentPhone.length != 11) {
						layer.msg('请输入正确的手机号码', {
							icon: 5
						});
						return false;
					}
					App.ajax({
						data: params,
						resUrl: "ygxStudent/update", // 修改的接口
						callback: function(rb) {
							if(!rb.status) {
								layer.msg(rb.msg, {
									icon: 5
								});
								return;
							}
							//隐藏编辑窗口
							App.closeEntitySlider();
							layer.msg(rb.msg, {
								icon: 1
							});
							_this.list();
						}
					});
				},
				//滑动窗口打开时的回调
				callback: function(e) {
					$("#entitySlider .detail-brand").find("vl").html("新增");
					if( data ){
						var $form = $(e);
						App.setFormData($form, data);
					}
					// 去程时间初始化
					$('#quchengshijian').dateRangePicker({
						autoClose: false,
						singleDate: true,
						timePicker: false,
						startOfWeek: 'Wednesday',
						format: 'YYYY-MM-DD',
						time: {
							enabled: false
						},
						callback: function() {
							if(_this.dayDiff($('#quchengshijian').val().split(' ')[0], $("#fanchengshijian").val().split(' ')[0]) <= 0) {
								$("#fanchengshijian").val('');
							}
							if($('#quchengshijian').val().split(' ')[0] != '') {
								var startTime = $('#quchengshijian').val().split(' ')[0];
								$("#fanchengshijian").dateRangePicker({
									startDate: startTime,
									endDate: '2020-12-31',
									autoClose: false,
									singleDate: true,
									timePicker: false,
									startOfWeek: 'Wednesday',
									format: 'YYYY-MM-DD',
									time: {
										enabled: false
									},
									callback: function() {}
								});
							}
						}
					});
					// 返程时间初始化
					$("#fanchengshijian").dateRangePicker({
						autoClose: false,
						singleDate: true,
						timePicker: false,
						startOfWeek: 'Wednesday',
						format: 'YYYY-MM-DD',
						time: {
							enabled: false
						},
						callback: function() {}
					});
					// 初始化地址事件
					_this.initAddress();
				}
			};
			App.drawDetailPanel(opt);
		},
		// 新增滑窗的表单事件
		initEventForm: function(){
			// 添加车辆点击
			$("body").delegate(".add_vehicle_btn", 'click', function() {
				var html = $("#add_vehicle_box").html();
				var $st = $(html);
				layer.confirm($st[0].outerHTML, {
					type: 0,
					title: "添加车辆",
					closeBtn: 1,
					area: ['600px', '400px'], //宽高
					btn: ['确定', '取消'] //按钮
				}, function() {
					
				}, function() {
					layer.msg('操作已取消', {
						icon: 7
					});
				});
			});
			// 添加车辆弹窗中按钮-操作
			$("body").delegate("#add_vehicle-div .avd_minus", 'click', function(){
				var $inp = $(this).parent().parent().find('input');
				var val = parseInt($inp.val()) - 1 ;
				if( val <= 0 ){
					$inp.val( 0 )
				}else{
					$inp.val( val )
				}
			});
			// 添加车辆弹窗中按钮+操作
			$("body").delegate("#add_vehicle-div .avd_add", 'click', function(){
				var $inp = $(this).parent().parent().find('input');
				var val = parseInt($inp.val()) + 1 ;
				$inp.val( val )
			});
			// 订单来源操作
			$("body").delegate("#add-div input[name=order_root]", 'click', function(){
				if( $(this).val() == 2 ){
					$('.ent_customer_box').removeClass('ent_customer_active').hide();
					$('input[name=pay_tyle_inp]').val('现金支付');
				}else{
					$('.ent_customer_box').addClass('ent_customer_active').show();
					$('input[name=pay_tyle_inp]').val('月结');
				}
			});
			// 复制同车型价格点击
			$("body").delegate("#add-div .copy_vehicle_btn", 'click', function(){
				var tr = $('#list-cost>tr').eq(0).html();
				var $tr = $('<tr>'+ tr +'</tr>');
				$('#list-cost').append($tr);
			});
		},
		// 其它事件初始化
		initEvent: function() {
			// 查询日期初始化
			$('#startDate').dateRangePicker({
				autoClose: false,
				singleDate: true,
				timePicker: false,
				startOfWeek: 'Wednesday',
				format: 'YYYY-MM-DD',
				time: {
					enabled: false
				},
				callback: function() {
					if(_this.dayDiff($('#startDate').val().split(' ')[0], $("#endDate").val().split(' ')[0]) <= 0) {
						$("#endDate").val('');
					}
					if($('#startDate').val().split(' ')[0] != '') {
						var startTime = $('#startDate').val().split(' ')[0];
						$("#endDate").dateRangePicker({
							startDate: startTime,
							endDate: '2020-12-31',
							autoClose: false,
							singleDate: true,
							timePicker: false,
							startOfWeek: 'Wednesday',
							format: 'YYYY-MM-DD',
							time: {
								enabled: false
							},
							callback: function() {}
						});
					}
				}
			});
			// 查询日期初始化
			$("#endDate").dateRangePicker({
				autoClose: false,
				singleDate: true,
				timePicker: false,
				startOfWeek: 'Wednesday',
				format: 'YYYY-MM-DD',
				time: {
					enabled: false
				},
				callback: function() {}
			});
			// 客户名称select2初始化
			$('#customerName').select2({
				placeholder: "客户名称",
				minimumInputLength: 0,
				allowClear: true,
				ajax: {
					url: App.getServicePath + 'station/select2',
					dataType: 'json',
					data: function(term, page) {
						return {
							key: encodeURI(term)
						};
					},
					results: function(data, page) {
						return {
							results: data.data
						};
					},
					processResults: function(data, params) {
						params.page = params.page || 1;

						return {
							results: data.results,
							pagination: {
								more: (params.page * 10) < data.count_filtered
							}
						};
					}
				}
			});
			// 客户经理select2初始化
			$('#refundRange').select2({
				placeholder: "客户名称",
				minimumInputLength: 0,
				allowClear: true,
				ajax: {
					url: App.getServicePath + 'station/select2',
					dataType: 'json',
					data: function(term, page) {
						return {
							key: encodeURI(term)
						};
					},
					results: function(data, page) {
						return {
							results: data.data
						};
					},
					processResults: function(data, params) {
						params.page = params.page || 1;

						return {
							results: data.results,
							pagination: {
								more: (params.page * 10) < data.count_filtered
							}
						};
					}
				}
			});
			// 付款状态select2初始化
			$('#ticketNo').select2({
				placeholder: "客户名称",
				minimumInputLength: 0,
				allowClear: true,
				ajax: {
					url: App.getServicePath + 'station/select2',
					dataType: 'json',
					data: function(term, page) {
						return {
							key: encodeURI(term)
						};
					},
					results: function(data, page) {
						return {
							results: data.data
						};
					},
					processResults: function(data, params) {
						params.page = params.page || 1;

						return {
							results: data.results,
							pagination: {
								more: (params.page * 10) < data.count_filtered
							}
						};
					}
				}
			});
			// 查询点击
			$searchForm.submit(function() {
				var params = $searchForm.serializeObject();
				curPage = 1;
				_this.list(params);
				return false;
			});
			// 更多滑窗中地址点击
			$("body").delegate(".addr_localtion", 'click', function() {
				console.log($(this))
				//App.singleMap =data;
                layer.open({
                    type: 2,
                    title: '查看地图位置',
                    shadeClose: true,
                    shade: false,
                    shade: 0.7,
                    area: ['914px', '636px'],
                    content: '/src/page/map/vehiclePos.html?v_=' + App.reandom()
                });
			});
			// 更多滑窗中支付查询点击
			$("body").delegate(".pay_btn", 'click', function() {
				console.log($(this))
				//点击后刷新支付的表格
			});
		},
		// 地址实时查询初始化
		initAddress: function(){
			initMapAutoSearch('addressStart');
			initMapAutoSearch('addressEnd');		
			
			$('#addWap').bind('click',function(){
				var num;
				if( $('.wayPoint').length >0 ){
					num = $('.wayPoint').length;
				}else{
					num = '0';
				}
				var str = '<div class="col-sm-12 wayPoint_box" style="margin-bottom: 10px;padding-left:70px;">'
		                + '<div class="input-group col-lg-8">'
	                    + '<span class="input-group-addon">途径点</span>'
						+ '<input type="text" class="form-control wayPoint" id="wayPoint'+ num +'" name="wayPoint'+ num +'" maxlength="50" autocomplete="off">'
	                    + '<span class="input-group-addon delete_way_btn" style="cursor:pointer;">-删除途径点</span>'
		                + '</div>'
				  		+ '</div>';
				$('#way_con').before(str);
				initMapAutoSearch('wayPoint' + num);
				
				$('#wayPoint' + num).parents('.wayPoint_box').find('.delete_way_btn').bind('click', function(){
					$('#wayPoint' + num).parents('.wayPoint_box').remove();
				})
			});
			
						//REGION START 这部分JS用于处理地图
			var map;
			var point;
			
			var province;
			var city;
			var address;
			var b_long;
			var b_lat;
			var myValue;
			
			
			var isAutoSearch = false;
			function initMapAutoSearch( obj ) {
				var ac = new BMap.Autocomplete(    //建立一个自动完成的对象
					{"input" : obj, "location" : map,
					onSearchComplete:function(){
						console.log(1111)
						if(isAutoSearch){
							ac.hide();
							isAutoSearch = false;
						}
					}
				});
			
				ac.addEventListener("onhighlight", function(e) {  //鼠标放在下拉列表上的事件
					var str = "";
					var _value = e.fromitem.value;
					var value = "";
					if (e.fromitem.index > -1) {
						value = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
					}    
					str = "FromItem<br />index = " + e.fromitem.index + "<br />value = " + value;
					
					value = "";
					if (e.toitem.index > -1) {
						_value = e.toitem.value;
						value = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
					}    
					str += "<br />ToItem<br />index = " + e.toitem.index + "<br />value = " + value;
					$("#searchResultPanel").innerHTML = str;
				});
			
				ac.addEventListener("onconfirm", function(e,target,item) {    //鼠标点击下拉列表后的事件
				var _value = e.item.value;
					myValue = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
					$("#searchResultPanel").innerHTML ="onconfirm<br />index = " + e.item.index + "<br />myValue = " + myValue;
					
					var geo = new BMap.Geocoder();
					geo.getPoint(myValue, function(point){
						if (point) {
						     //经度
						     var pointx = point.lng;
						     //纬度
						     var pointy = point.lat;
						     
						    $('#' + obj).data('lng', pointx);
						    $('#' + obj).data('lat', pointy);
						    
						}
					}, _value.city);
					
				});
				
				$("#address").on("change", function(){
					 province = '';
				    city = '';
				    address = '';
						 b_long = '';
				    b_lat = '';
				});
			}
		},
		// 两个日期的天数差，参数格式：'YYYY-MM-DD HH:mm:ss'
		dayDiff: function(startDate, endDate) {
			var beginTime = startDate;
			var endTime = endDate;
			var beginDate = new Date(beginTime);
			var endDate = new Date(endTime);
			var day = (endDate.getTime() - beginDate.getTime()) / (24 * 60 * 60 * 1000) + 1;
			return day;
		},
		parse: function() {
			listHtml = $dataList.html();
			//$dataList.empty();
		},
		init: function() {
			_this.parse();
			_this.initEvent();
			_this.initEventList();
			_this.initEventCarList();
			_this.initEventHeadBtn();
			_this.initEventForm();
			_this.list();
		}
	}
	_this.init(); //页面初始化入口设置
})();